'use strict';

/**
 * @ngdoc function
 * @name magisterkaGuiApp.controller:AlgorithmSimpleCtrl
 * @description
 * # AlgorithmSimpleCtrl
 * Controller of the magisterkaGuiApp
 */
angular.module('magisterkaGuiApp')
    .controller('AlgorithmRaceCtrl', function ($scope, $log) {


        $scope.init = function () {
            $log.debug('alg race inited');
            $log.debug(event);
            $scope.$watch('event', function (newValue, oldValue) {
                var results = createDisplayResults(newValue);
                $scope.display = {
                    results: results
                }
            });
        }

        function createDisplayResults(event) {

            var results = [];
            angular.forEach(event.algorithmState.peopleProgresses, function (progressData) {
                angular.forEach(event.people, function (personData) {
                    if (progressData.id == personData.id) {
                        results.push({
                            id: personData.id,
                            name: personData.name,
                            profileImageUrl: personData.profileImageUrl,
                            percentFinished: progressData.percentFinished ? progressData.percentFinished : 0
                        });

                    }
                });
            });

            return results;

        }


    });
